Previous Book Contents Book Index Next

Inside Macintosh: Open Transport /
Chapter 3 - Endpoints / Endpoints Reference
Functions / Checking a Buffer's Size


OTCountDataBytes

Returns the amount of data currently available to be handled.

C INTERFACE
OTResult OTCountDataBytes(EndpointRef ref, size_t* countPtr);
C++ INTERFACE
OTResult TEndpoint::CountDataBytes(size_t* countPtr);
PARAMETERS
ref
The endpoint reference of the endpoint to which the data has been sent and which will be reading or otherwise using the data.
countPtr
A pointer to a buffer containing the size (in bytes) of the data in the topmost packet or stream buffer.
DESCRIPTION
If the function returns successfully, the countPtr parameter points to a buffer containing the the number of bytes in the message buffer at the top of the stream. How you might want to handle the data depends on which event is outstanding. For example, if you have a T_DATA outstanding, then the buffer indicates the data available to be read; if you have a T_DISCONNECT outstanding, then the buffer indicates the number of bytes in the disconnect.

Additionally, what the function counts depends on the type of endpoint. If it is packet-oriented, the function counts the number of bytes in the topmost packet; if it's stream-oriented, the function counts the total amount of nonexpedited data or the amount of expedited data in the topmost buffer at stream head. That is, if nonexpedited data was received in more than one piece, the function provides a count of the sum of the pieces, but if expedited data was received in multiple parts, the function only provides a count of the data in the topmost buffer.

If the buffer points at data to be read, this does not mean that this is all the data that was sent. You might need to do additional reads to get the rest of the data. You can call this function upon receipt of a T_DATA event to find out how much data is currently available and to determine whether you need to allocate larger buffers before calling a function that reads the data.

Because what this function counts depends on which event is the most current outstanding event and other events can occur before the function can complete, never use this count as more than a hint.

VALID STATES
All


Previous Book Contents Book Index Next

© Apple Computer, Inc.
15 AUG 1996